#pragma once
#include "Template.h"
#include "Person.h"
#include "InterestTable.h"
#include "Dating.h"
#include <string>
#include <istream>
#include <iostream>

using namespace std;

class PersonList
{
	friend class Dating;
private:
	string filename;
	List<Person> boysList;
	List<Person> girlsList;
	Person p;

public:
	PersonList (PersonList &pList)
	{
		this->filename = pList.filename;
		this->boysList = pList.boysList;
		this->girlsList = pList.girlsList;
		this->p = pList.p;
		this->p.interestList = pList.p.interestList;
	}

	PersonList& operator=(PersonList &pList)
	{
		this->filename = pList.filename;
		this->boysList = pList.boysList;
		this->girlsList = pList.girlsList;
		this->p = pList.p;
		this->p.interestList = pList.p.interestList;
		return *this;
	}

	PersonList()
	{
		filename = "";
	}

	~PersonList(){}

	void readFromFile(string filename)
	{
		ifstream fin;
		int k= 0;
		fin.open(filename);
		string input;
		
		while(!fin.eof())
		{
			fin>>input;
			if(k == 0)
				p.name = input;
			if(k == 1)
			{
				if(input == "Girl")
					p.gender = "Girl";
				if(input == "Boy")
					p.gender = "Boy";
			}
			if(input == "#")
			{
				if(p.gender == "Girl")
					girlsList.addAtHead(p);
				if(p.gender == "Boy")
					boysList.addAtHead(p);
				p.interestList.head = nullptr;
				p.interestList.tail = nullptr;
				k = 0;
			}
			else if (k > 1)
			{
				p.interestList.addAtHead(input);
			}
			else
				k++;
		}
		fin.close();
	}

	void Match()
	{
		PersonList pl;
		Dating d;
		int commonInterests;
		cout << endl << "Specify amount of mutual interests: ";
		cin >> commonInterests;
		d.findMatch(commonInterests, girlsList, boysList);
	}
};